package com.by.service.impl;

import com.by.entity.ErpProductInquirySheet;
import com.by.mapper.ErpProductInquirySheetMapper;
import com.by.service.ErpProductInquirySheetService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

/**
 * @author: Fsw
 * @com.by.service.impl
 * @date 2025-02-26 20:05
 */
@Service
public class ErpProductInquirySheetServiceImpl implements ErpProductInquirySheetService {
    @Autowired
    private ErpProductInquirySheetMapper erpProductInquirySheetMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param sn 主键
     * @return 实例对象
     */
    public ErpProductInquirySheet queryById(String sn){
        return erpProductInquirySheetMapper.queryById(sn);
    }

    /**
     * 分页查询
     *
     * @param erpProductInquirySheet 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    public Page<ErpProductInquirySheet> paginQuery(ErpProductInquirySheet erpProductInquirySheet, PageRequest pageRequest){
        long total = erpProductInquirySheetMapper.count(erpProductInquirySheet);
        return new PageImpl<>(erpProductInquirySheetMapper.queryAllByLimit(erpProductInquirySheet, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param erpProductInquirySheet 实例对象
     * @return 实例对象
     */
    public ErpProductInquirySheet insert(ErpProductInquirySheet erpProductInquirySheet){
        erpProductInquirySheetMapper.insert(erpProductInquirySheet);
        return erpProductInquirySheet;
    }

    /**
     * 更新数据
     *
     * @param erpProductInquirySheet 实例对象
     * @return 实例对象
     */
    public ErpProductInquirySheet update(ErpProductInquirySheet erpProductInquirySheet){
        erpProductInquirySheetMapper.update(erpProductInquirySheet);
        return queryById(erpProductInquirySheet.getSn());
    }

    /**
     * 通过主键删除数据
     *
     * @param sn 主键
     * @return 是否成功
     */
    public boolean deleteById(String sn){
        int total = erpProductInquirySheetMapper.deleteById(sn);
        return total > 0;
    }
}
